package designPatterns.P02_工厂模式_Factory.P01_简单工厂.P01_PizzaStore.第2版_简单工厂.order;

import Utils.io.IOUtils;
import designPatterns.P02_工厂模式_Factory.P01_简单工厂.P01_PizzaStore.第2版_简单工厂.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;

/**
 * @author d11yu
 */
public class OrderPizza {
    private SimpleFactory factory;
    private Pizza pizza = null;

    public OrderPizza(SimpleFactory factory) {
        this.factory = factory;
    }

    public void order() {
        do {
            pizza = this.factory.createPizza(getType());
            if (pizza == null) {
                break;
            }
            this.pizza.prepare();
            this.pizza.bake();
            this.pizza.cut();
            this.pizza.box();
        } while (true);
    }

    private String getType() {
        BufferedReader br = IOUtils.getConsoleInput();
        System.out.print("input pizza type:");
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }
}
